<?php

namespace App\Providers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        \Carbon\Carbon::setLocale('zh');

        if(!app()->runningInConsole() && env('APP_DEBUG')){
            DB::listen(function ($query) {
                $tmp = str_replace('?', '"' . '%s' . '"', $query->sql);
                $tmp = @vsprintf($tmp, $query->bindings);
                $tmp = str_replace("\\", "", $tmp);
                Log::channel("sql")->debug(' execution time: ' . $query->time . 'ms; ' . $tmp . "\t");
            });
        }
    }
}
